import { Table, message, notification, Tooltip,Avatar,Result } from 'antd';
import { Component } from 'react';

export default class SelfTable extends Component {
  constructor() {
    super();
    this.state = {
      columns: [],
    };
  }
  selfRender = (text) => (
    <span
      style={{
        display: 'block',
        textOverflow: 'ellipsis',
        overflow: 'hidden',
        wordBreak: 'keep-all',
        whiteSpace: 'nowrap',
      }}
    >
      <Tooltip title={text}>{text}</Tooltip>
    </span>
  );

  componentDidUpdate(nextProps, nextContext) {
    console.log(nextProps);
  }
  render() {
    const { keyid, dataSource, columns, ...selfProps } = this.props;
    columns.forEach((item, index) => {
      // let _self = this
      if(item.render){
        columns[index]['align'] = 'center';
      }else{
        columns[index]['render'] = (text) => this.selfRender(text);
        columns[index]['align'] = 'center';
      }
    });
    return (
      <div>
        {this.props.isshowHeader?<Result
                style={{height:'200px',padding:'10px 32px'}}
                    status="success"
                    icon={<Avatar size={98} src='/logo.svg' />}
                    title={this.props.msg?this.props.msg:"XXX学校校医院病例系统"}
                    subTitle={this.props.msg?"XXX学校校医院病例系统":''}
                />:<></>}
        <Table
          key={keyid}
          dataSource={dataSource}
          {...selfProps}
          columns={columns}
        ></Table>
      </div>
    );
  }
}
